package com.hs.bai.controller;

import com.hs.bai.pojo.AdditionalGoodsinfo;
import com.hs.bai.service.IAdditionalGoodsinfoService;
import com.hs.dto.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Dingkun Bai
 * @since 2022-06-18
 */
@CrossOrigin
@RestController
@RequestMapping("/additionalGoodsinfo")
public class AdditionalGoodsinfoController {

    @Autowired
    private IAdditionalGoodsinfoService additionalGoodsinfoService;

    /**
     * 添加货物总信息
     * @param additionalGoodsinfo
     * @return
     */
    @PostMapping("/add/{orderId}")
    public ResultBean addAdditionalGoodsinfo(@PathVariable String orderId ,@RequestBody AdditionalGoodsinfo additionalGoodsinfo){

        additionalGoodsinfo.setOrderId(orderId);
        additionalGoodsinfo.setGoodType("普通货物");
        boolean b = additionalGoodsinfoService.save(additionalGoodsinfo);

        return b ? ResultBean.OK("添加成功！"):ResultBean.ERROR("添加失败！");

    }

    /**
     * 修改货物信息
     * @param orderId
     * @param additionalGoodsinfo
     * @return
     */
    @PostMapping("/update/{orderId}")
    public ResultBean updateAdditionalGoodsinfo(@PathVariable String orderId ,@RequestBody AdditionalGoodsinfo additionalGoodsinfo){

        additionalGoodsinfo.setOrderId(orderId);
        additionalGoodsinfo.setGoodType("普通货物");
        return additionalGoodsinfoService.updateById(additionalGoodsinfo) ? ResultBean.OK("修改成功！"):ResultBean.ERROR("修改失败！");

    }

}
